package main

import "fmt"

func main() {
	var r Rect
	r.width=1
	r.height=2
	fmt.Print(r.Area())



//初始化
	rect1 := new(Rect)
	rect2 := &Rect{}
	rect3 := &Rect{0, 0, 100, 200}
	rect4 := &Rect{width: 100, height: 200}
	fmt.Println(rect1,rect2,rect3,rect4)


}
type Rect struct {
	x,y float64
	width,height float64
}
func (r Rect) Area () float64{ //定义方法 归属于Rect类
	return r.width*r.height
}
func NewRect(x, y, width, height float64) *Rect {//NewXXX构造方法
	return &Rect{x, y, width, height}
}